package com.lys.item;

import com.lys.enchantment.ModEnchantments;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentLevelEntry;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class ModItemGroups {

    public static final String MOD_GROUP_TRANSLATION_KEY = "item_group_more_enchants";

    public static final RegistryKey<ItemGroup> MORE_ENCHANTMENTS = ModItemGroups.register("more_enchantments");

    public static void registerMoreEnchantmentGroup() {
        Registry.register(Registries.ITEM_GROUP, MORE_ENCHANTMENTS, ItemGroup.create(ItemGroup.Row.TOP, 0)
                .displayName(Text.translatable(MOD_GROUP_TRANSLATION_KEY))
                .icon(() -> new ItemStack(ModItems.ITEM_GROUP_ICON)).entries((displayContext, entries) -> {
                    for (Enchantment enchantment : ModEnchantments.Enchantments) {
                        ItemStack itemStack = EnchantedBookItem.forEnchantment(new EnchantmentLevelEntry(enchantment, enchantment.getMaxLevel()));
                        entries.add(itemStack,ItemGroup.StackVisibility.PARENT_TAB_ONLY);
                    }
                }).build());
    }

    private static RegistryKey<ItemGroup> register(String id) {
        return RegistryKey.of(RegistryKeys.ITEM_GROUP, new Identifier(id));
    }

}
